#!/usr/bin/env node

const mysql=require('mysql2/promise');

//创建联接
let con=mysql.createPool({
  host:'localhost',
  user:'root',
  password:'ddd',
  database:'test'

});

async function getAreas(){
  const sql='select * from areas';
  let [rows]=await con.execute(sql);
  console.log(rows);
}
async function addAreas(areaName){

  const sql=`insert into areas(area_name) values('${areaName}')`;
  let [rows]=await con.execute(sql);
  console.log(rows);
  return rows;

}

(async function (){
  await getAreas(); 
})()

async function updateAreas(oldName,newName){
  const sql=`update areas set area_name='${newName}' where area_name='${oldName}'`;
  let [rows]=await con.execute(sql);
  console.log([rows]);
}

(async function(){
  await addAreas('hh');
})()



(async function(){
  await updateAreas('英国','大不列');
})()


